1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  package net.sf.pmr.keopsframework.domain.validation;
38  
39  import java.util.List;
40  import java.util.Locale;
41  
42  /***
43   * @author Arnaud Prost (arnaud.prost@gmail.com)
44   *
45   * Interface de la structure d'erreur
46   * Elle est largement inspirée de celle du framework Spring à différence:
47   * - elle a été simplifiée en supprimant certaines méthodes
48   *
49   */
50  public interface Errors {
51  
52  
53      /***
54       * Reject the current object, using the given error description.
55       * @param errorCode
56       */
57      void reject(final String errorCode);
58  
59      /***
60       * Reject the current object, using the given error description.
61       * @param errorCode
62       * @param errorArguments
63       */
64      void reject(final String errorCode, final Object[] errorArguments);
65  
66      /***
67      * Reject the given field of the current object, using the given error description.
68       * @param field
69       * @param errorCode
70      */
71      void rejectValue(final String field, final String errorCode);
72  
73      /***
74       * Reject the given field of the current object, using the given error description.
75       * @param field
76       * @param errorCode
77       * @param errorArguments
78       */
79       void rejectValue(final String field, final String errorCode, final Object[] errorArguments);
80  
81  
82      /***
83       * public boolean hasErrors()
84       * @return boolean
85       */
86        boolean hasErrors();
87  
88        /***
89         * Return the total number of errors.
90         * @return int
91         */
92        int getErrorCount();
93  
94       
95       /***
96        * Get all errors, both global and field ones.
97        * @param locale locale
98        * @return List of errors
99        */
100       List getAllErrors(Locale locale);
101       
102       /***
103        * Get all the message parameters for all errors, both global and field ones.
104        * @param locale locale
105        * @return List of errors
106        */
107        List getAllErrorsMessageParameters();
108 
109 
110     /***
111      * Return if there were any global (i.e. not field-specific) errors.
112      * @return boolean
113      */
114      boolean hasGlobalErrors();
115 
116      /***
117       * Return if there are any errors associated with the given field.
118       * @param field
119       * @return boolean
120       */
121       boolean hasFieldErrors(final String field);
122 
123     /***
124      * Return the number of global (i.e. not field-specific) errors.
125      * @return number of errors
126      */
127      int getGlobalErrorCount();
128     
129     /***
130      * Get the first global error, if any.
131      * @param locale locale
132      * @return number of errors 
133      */
134      String getGlobalError(Locale locale);
135 
136     
137     /***
138      *  Get all global errors.
139      * @param locale locale
140      * @return list list
141      */
142     List getGlobalErrors(Locale locale);
143 
144 
145     /***
146      * Return the number of errors associated with the given field.
147      * @param field name of the field
148      * @return int number or errors for the field
149      */
150      int getFieldErrorCount(final String field);
151 
152     
153     /***
154      * Get the first error associated with the given field, if any.
155      * @param field field
156      * @param locale locale
157      * @return String
158      */
159      String getFieldError(final String field, final Locale locale);
160 
161      
162     /***
163      * Get all errors associated with the given field.
164      * @param field field
165      * @param locale locale
166      * @return List list 
167      */
168     List getFieldErrors(final String field, final Locale locale);
169 
170 }